from pytube import YouTube

#This line takes the youtube link as input
link=raw_input("Enter the link you wanna download:")
ch = ""
try:
    # "ch" stores the user's choice of an audio or video
    ch = input("What do you want to download audio or video? Press 1 for audio and anyother key for video")
    global yt
    yt = YouTube(link)
except :
    print("There is a connection error Or see if you have entered a proper Youtube video link ")
    input()
    
if (ch==1):
    mp4files = yt.streams.filter(only_audio=True).all()
    #"yt.streams.filter(only_audio=True).all()" returns all the steams with the audio track
    mp4files[0].download("D:/", filename= yt.title+"-- Audio")
    print("Download complete !! If your audio player does not support the audio file .  use vlc media player ")
else:
    mp4files = yt.streams.filter(file_extension='mp4').all()
    #"yt.streams.filter(file_extension='mp4').all()" returns all the steams with the video plus audio
    mp4files[0].download("D:/",filename= yt.title+"-- Video")
    print("Download complete !! If your audio player does not support the audio file .  use vlc media player ")

print(" File has been saved to drive D:/ ")

input()
